package org.quadraspace.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@XmlRootElement
@Entity
public class Event {

	@Id
	@GeneratedValue
	private Long theId;

	@XmlTransient
	public Long getTheId() {
		return theId;
	}

	public void setTheId(Long theId) {
		this.theId = theId;
	}

	private Date timestamp = new Date();
	private long delay;

	public static enum Type {
		sample, heartbeat
	};

	private Type type = Type.sample;
	private String moteId = null;
	
	@XmlAttribute
	public long getTimestamp() {
		return timestamp.getTime();
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = new Date(timestamp);
	}

	@XmlAttribute
	public long getDelay() {
		return delay;
	}

	public void setDelay(long delay) {
		this.delay = delay;
	}

	@XmlAttribute
	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private Source source = new Source();

	@XmlElement
	public Source getSource() {
		return source;
	}

	public void setSource(Source source) {
		this.source = source;
	}

	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private Location location = new Location();

	@XmlElement(name = "location")
	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private EventData data = new EventData();

	@XmlElement
	public EventData getData() {
		return data;
	}

	public void setData(EventData data) {
		this.data = data;
	}

	@XmlTransient
	public String getMoteId() {
		return moteId;
	}

	public void setMoteId(String moteId) {
		this.moteId = moteId;
	}
}
